package cn.shop.transcation.detail.mapper;

import cn.shop.base.MyPage;
import cn.shop.transcation.detail.entity.FundDetail;
import cn.shop.transcation.detail.entity.TransactionDetail;
import cn.shop.transcation.detail.entity.TransactionRecordQueryReq;
import cn.shop.transcation.detail.entity.WithdrawDetail;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author : 李一涵
 * @date : Created in 2021-11-8 13:59
 * @description : mapper
 */
@Mapper
public interface FundDetailMapper extends BaseMapper<FundDetail> {

	/**
	 * 获取交易明细列表
	 *
	 * @param page   分页
	 * @param userId 用户编号
	 * @param req    查询条件
	 * @return 交易明细列表
	 * @author 李一涵
	 * @since 2022-02-22
	 */
	Page<TransactionDetail> detailList(Page<TransactionDetail> page,
	                                   @Param("userId") Long userId,
	                                   @Param("req") TransactionRecordQueryReq req);

	/**
	 * 获取交易明细列表(买入和卖出)
	 * @param page
	 * @param userId
	 * @param req
	 * @return
	 */
	Page<TransactionDetail> detailList2(Page<TransactionDetail> page,
									   @Param("userId") Long userId,
									   @Param("req") TransactionRecordQueryReq req);

	/**
	 * 获取交易明细列表(充值和提现)
	 * @param page
	 * @param userId
	 * @param req
	 * @return
	 */
	Page<TransactionDetail> detailList3(Page<TransactionDetail> page,
									   @Param("userId") Long userId,
									   @Param("req") TransactionRecordQueryReq req);

	Map<String, BigDecimal> sumAmount(@Param(Constants.WRAPPER) LambdaQueryWrapper<FundDetail> wrapper);

	Map<String, Object> sumAmountQuery(@Param("req") TransactionRecordQueryReq req);

	MyPage<WithdrawDetail> queryByPageForWithdraw(@Param("page") MyPage<FundDetail> page, @Param(Constants.WRAPPER) QueryWrapper<FundDetail> query);

	Map<String, BigDecimal> sumAmountForWithdraw(@Param(Constants.WRAPPER) QueryWrapper<FundDetail> wrapper);

	long countForWithdraw(@Param(Constants.WRAPPER) QueryWrapper<FundDetail> wrapper);

	Long getMerchantIdByAlias(@Param("alias") String alias);

}
